let managerComponent = {
    template: `
        <div class="manager page">
            <div class="head">
                <div class="left"></div>
                <div class="title">Manager</div>
                <div class="right"></div>
            </div>
            <div class="filter">
                <div class="filter-item">
                    <div class="label">name</div>
                    <div class="input">
                        <input type="text" v-model="filter.name">
                    </div>
                </div>
                <div class="filter-item">
                    <div class="label">author</div>
                    <div class="input">
                        <input type="text" v-model="filter.description">
                    </div>
                </div>
                <div class="btn" @click="fetchDataList">filter</div>
            </div>
            <div class="main">
               <div class="content">
                   <div class="item" v-for="item in categoryList" @click="handleView(item)">
                        <div class="item-name">{{item.name}}</div>
                        <div class="publisher">{{item.description}}</div>
                        <div class="controls">
                            <div class="btn" @click.stop="update(2,item)" v-show="item.state === 1">Publish</div>   
                            <div class="btn" @click.stop="update(1,item)" v-show="item.state === 2">Unline</div>   
                        </div>
            
                    </div>
               </div>

          
            </div>
        </div>
    `,
    data() {
        return {
            categoryList:[],
            filter:{
                name:null,
                description:null
            }
        }

    },
    computed: {},
    watch: {},
    mounted() {
        this.fetchDataList()
    },
    activated() {

    },
    methods: {
        fetchDataList(){
            let filter = {
                state:{"op":"IN","value":[1,2]}
            }
            if(this.filter.name){
                filter.name = {
                    op:'LIKE',
                    value: '%' + this.filter.name + '%'
                }
            }
            if(this.filter.description){
                filter.description = {
                    op:'LIKE',
                    value: '%' + this.filter.description + '%'
                }
            }
            treatmentSession.getList(JSON.stringify(filter)).then((entities)=>{

                entities.sort(function(a,b){return b.id-a.id})

                this.categoryList = entities
            })
        },
        update(state,item){
            treatmentSession.update({
                id: item.id,
                state
            }).then(()=>{
                item.state = state
            })
        },
        handleView(item){
            this.$router.push({
                name:'detail',
                query:{
                    sessionId: item.id
                }
            })
        }
    },
    components: {},
    beforeRouteLeave(to, from, next) {

        next();
    }
}

